<?php

class model_dbm_orm extends model_dbm {

    public function q($string_query = NULL) {
        return $this->query($string_query);
    }
    
    public function getDatabaseInfo() {
        $provisorio = array();
        $tabelas = array();

        $r = $this->qcv("SHOW TABLES", "*");

        foreach ($r as $v) {
            foreach ($v as $v2) {
                array_push($provisorio, $v2);
            }
        }
        
        foreach ($provisorio as $v) {
            array_push($tabelas, array($v => $this->getColumnNames($v)));
        }
        return $tabelas;
    }

    protected function getColumnNames($tabela) {
        
        $columns = array();
        
        $this->q("SELECT * FROM $tabela LIMIT 1");

        $i = 0;
        while ($i < mysql_num_fields($this->query)) {
            $meta = mysql_fetch_field($this->query, $i);
            
            $columns[$meta->name] = array($meta->primary_key, $meta->not_null);
            $i++;
        }
        mysql_free_result($this->query);
        return $columns;
    }

}

?>